/**
 * 构造/析构顺序：
 * 1. 构造函数: 先调用基类的构造函数，再调用子类的构造函数
 * 2. 析构函数：先调用子类的析构函数，再调用基类的析构函数
 * 3. 对于多继承，按照从左到右顺序构造，按照从右到左顺序析构
 */
#include <iostream>

using namespace std;

class Base1 {
public:
    Base1() { cout << "Construct Base1" << endl; }

    virtual ~Base1() { cout << "Destruct Base1" << endl; }
};

class Base2 {
public:
    Base2() { cout << "Construct Base2" << endl; }

    virtual ~Base2() { cout << "Destruct Base2" << endl; }

};

class Derived : public Base1, public Base2 {
public:
    Derived() { cout << "Construct Derived" << endl; }

    ~Derived() override { cout << "Destruct Derived" << endl; }
};


void test1() {
    cout << "test1:" << endl;
    Derived d;
}

void test2() {
    cout << "test2:" << endl;
    Base2 *b1 = new Derived();
    delete b1; // 如果 Base2 的析构函数非虚，则只会调用 Base2 的析构函数
}

int main() {
    test1();
    test2();
    return 0;
}